package com.fixme4trade.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;


@Entity 
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class MessageList implements Serializable {
	
	private static final long serialVersionUID = 1L;

	@Id
	//@GeneratedValue(strategy = GenerationType.AUTO)
	@GeneratedValue(strategy = GenerationType.TABLE)
	@Column(name="message_list_id")
	private Long id;
	
	@OneToMany(mappedBy = "messageList")	
	private List<Message> messages;
	
	public MessageList() {
		
	}
	
	public List<Message> getMessages() {
		return messages;
	}

	public void setMessages(final List<Message> messages) {
		this.messages = messages;
	}	

	public Long getId() {
		return id;
	}

	public void setId(final Long id) {
		this.id = id;
	}
	
	public void addMessage(final Message message) {
		if (messages == null) 
			messages = new ArrayList<Message>();
		
		message.setMessageList(this);
		messages.add(message);
	}
}
